using COC.Debug;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using COC.Tool;
using COC.Service;
namespace COC.CEvent{
	public class CEventDispatcher:UnityEngine.Object
{
	private CSelection selector{get;set;}
	public void Dispatch(CEventHandler handler){
			List<CTuple<CEventType,int,IService>> s=selector.GetSelector();
			CEventType t=handler.type;
			foreach(CTuple<CEventType,int,IService> c in s){
                DebugTool.Log("c:" + c.Item1.ToString() + " ;" + handler.source.ToString());
				if((int)(c.Item1)==(int)t&&c.Item2==CSelection.ACTIVE){
					IService service=c.Item3;
					service.SubscribeEvent(handler);
				}
			}
	}
		public CEventDispatcher(CSelection selector){
			this.selector=selector;
		}
		private static CEventDispatcher singleton;

		public static CEventDispatcher Instance(CSelection selector){
			if(singleton==null){
				singleton=new CEventDispatcher(selector);
			}
			return singleton;
		}
}

}